﻿using WorkTool2.Classes.Data;
using WorkTool2.Enums;

namespace WorkTool2.Helpers;

public static class CalendarHelper
{
    /// <summary>
    /// 日历每列宽度
    /// </summary>
    public static int _calendarColumnWidth = 13;

    public static List<CalendarData> GetCalendarSettings(int year)
    {
        var result = new List<CalendarData>();
        if (SettingsHelper._calendarSettings?.Count > 0)
        {
            var calendarSetting = SettingsHelper._calendarSettings.FirstOrDefault(x => x.Year.Equals(year));
            if (calendarSetting != null)
            {
                foreach (var month in calendarSetting.Data)
                {
                    foreach (var item in month.Dayoff)
                    {
                        var calendarData = new CalendarData
                        {
                            Date = new DateTime(year, month.Month, item.Day),
                            CalendarDateStatus = CalendarDateStatus.DayOff,
                            Description = item.Description,
                        };
                        result.Add(calendarData);
                    }
                    foreach (var item in month.Workdays)
                    {
                        var calendarData = new CalendarData
                        {
                            Date = new DateTime(year, month.Month, item.Day),
                            CalendarDateStatus = CalendarDateStatus.WorkingDays1,
                            Description = item.Description,
                        };
                        result.Add(calendarData);
                    }
                    foreach (var item in month.Custom)
                    {
                        var calendarData = new CalendarData
                        {
                            Date = new DateTime(year, month.Month, item.Day),
                            CalendarDateStatus = CalendarDateStatus.Custom,
                            Description = item.Description,
                        };
                        result.Add(calendarData);
                    }
                }
            }
        }
        return result;
    }
}